<?php

namespace App\Jobs\RongCloud;

use App\Jobs\Job;
use Illuminate\Support\Facades\Log;

class UserPushJob extends Job
{
    public $senderId;

    public $targetId;

    public $content;

    public $type;

    public $isIncludeSender;

    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct($senderId, $targetId, $content, $type = 'RC:CmdMsg', $isIncludeSender = 0)
    {
        $this->senderId = $senderId;
        $this->targetId = $targetId;
        $this->content = $content;
        $this->type = $type;
        $this->isIncludeSender = $isIncludeSender;
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        /**
         * @var $rcService \App\Services\Tools\RongCloudService
         */
        $rcService = app('rongcloud');
        // $result = $rcService->userPush($this->senderId, $this->targetId, $this->content, $this->type, $this->isIncludeSender);
        if ($this->senderId == 'system') {
            $result = $rcService->systemPushUser($this->senderId, $this->targetId, $this->content, $this->type);
            Log::error('roomConnectionJob:' . json_encode(['user_id' => $this->targetId, 'time' => getMillisecond(), 'data' => $this->content]));
        } else {
            $result = $rcService->userPush($this->senderId, $this->targetId, $this->content, $this->type, $this->isIncludeSender);
            Log::error('UserPushJob:' . json_encode(['user_id' => $this->targetId, 'time' => getMillisecond(), 'data' => $this->content]));
        }
//        dump($this->senderId, $this->targetId);
//        dump($result, $this->content);
    }
}
